from django.http import HttpResponse
from django.template import Context, loader
from django.core.mail import send_mail
from django.shortcuts import render_to_response
from django.http import HttpResponseRedirect
from Employees.models import *
from documents.models import Contract


from django import forms


class ContactForm(forms.Form):
    subject = forms.CharField()
    email = forms.EmailField(required=False)
    message = forms.CharField()



def contact(request):
    if request.method == 'POST':
        form = ContactForm(request.POST)
        if form.is_valid():
            cd = form.cleaned_data
            send_mail(
                cd['subject'],
                cd['message'],
                cd.get('email', 'noreply@example.com'),
                ['siteowner@example.com'],
            )
            return HttpResponseRedirect('Employees/form.html')
    else:
        form = ContactForm()
    return render_to_response('Employees/form.html', {'form': form})


def index(request):
    employee_list = Employee.objects.all()
    template = loader.get_template('Employees/index.html')
    contracts = Contract.objects.filter(active=True)
    context = Context({
        'employee_list': employee_list,
        'contracts' : contracts
        })
    return HttpResponse(template.render(context))


def details(request):
    employee_list = Employee.objects.all()
    template = loader.get_template('Employees/index.html')
    contracts = Contract.objects.filter(active=True)
    context = Context({
        'employee_list': employee_list,
        'contracts' : contracts
    })
    return HttpResponse(template.render(context))

def details(request):
    employee_list = Employee.objects.all()
    template = loader.get_template('Employees/form.html')
    contracts = Contract.objects.filter(active=True)
    context = Context({
        'employee_list': employee_list,
        'contracts' : contracts
    })
    return HttpResponse(template.render(context))